@extends('voyager::master')

@section('page_title',trans('voyager.View').$dataType->display_name_singular)

@section('page_header')
    <h1 class="page-title">
        <i class="{{ $dataType->icon }}"></i> @lang('voyager.View'){{ ucfirst($dataType->display_name_singular) }} &nbsp;

        @if (Voyager::can('edit_'.$dataType->name))
        <a href="{{ route('voyager.'.$dataType->slug.'.edit', $dataTypeContent->getKey()) }}" class="btn btn-info">
            <span class="glyphicon glyphicon-pencil"></span>&nbsp;
            @lang('voyager.Edit')
        </a>
        @endif
        <a href="{{ route('voyager.'.$dataType->slug.'.index') }}" class="btn btn-warning">
            <span class="glyphicon glyphicon-list"></span>&nbsp;
            @lang('voyager.Return to List')
        </a>        
    </h1>
    @include('voyager::multilingual.language-selector')
@stop

@section('content')
    <div class="page-content container-fluid">
        <div class="row">
            <div class="col-md-12">

                <div class="panel panel-bordered" style="padding-bottom:5px;">

                    <!-- /.box-header -->
                    <!-- form start -->

                    @foreach($dataType->readRows as $row)
                        @php $rowDetails = json_decode($row->details); @endphp

                        <div class="panel-heading" style="border-bottom:0;">
                            <h3 class="panel-title">{{ $row->display_name }}</h3>
                        </div>

                        <div class="panel-body" style="padding-top:0;">
                            @if($row->type == "image")
                                <img src="@if( strpos($dataTypeContent->{$row->field}, 'http://') === false && strpos($dataTypeContent->{$row->field}, 'https://') === false){{ Voyager::image( $dataTypeContent->{$row->field} ) }}@else{{ $dataTypeContent->{$row->field} }}@endif" style="width:100px">

                            @elseif($row->type == 'multiple_images')
                                <?php
                                $foreachImg = json_decode($dataTypeContent->{$row->field});
                                $foreachImg = $foreachImg?:array();
                                ?>
                                @foreach($foreachImg as $v)
                                    <img class="img-responsive"
                                         src="{{ Voyager::image($v) }}" style="display: inline-block;width: 200px;height: 200px">
                                @endforeach
                            @elseif($row->type == 'area')
                                <?php
                                $area = \App\Area::where('area_id',$dataTypeContent->{$row->field})->first();
                                ?>
                                {{$area->area_name or ''}}
                            @elseif($row->type == 'select_dropdown' && isset($rowDetails->options) &&
                                    !empty($rowDetails->options->{$dataTypeContent->{$row->field}})
                            )

                                <?php echo $rowDetails->options->{$dataTypeContent->{$row->field}};?>
                            @elseif($row->type == 'select_dropdown' && isset($rowDetails->relationship))
                                @if( !method_exists( $dataType->model_name, camel_case($row->field) ) )
                                    <p class="label label-warning"><i class="voyager-warning"></i> Make sure to setup the appropriate relationship in the {{ camel_case($row->field) . '()' }} method of the {{ $dataType->model_name }} class.</p>
                                @else
                                    <?php
                                    $relationshipListMethod = camel_case($row->field) . 'List';
                                    if (method_exists($dataTypeContent, $relationshipListMethod)) {
                                        $relationshipOptions = $dataTypeContent->$relationshipListMethod();
                                    } else {
                                        $relationshipClass = $dataTypeContent->{camel_case($row->field)}()->getRelated();

                                        if (isset($rowDetails->relationship->where)) {
                                            $relationshipOptions = $relationshipClass::where(
                                                $rowDetails->relationship->where[0],
                                                $rowDetails->relationship->where[1]
                                            )->get();
                                        } else {
                                            $relationshipOptions = $relationshipClass::where(
                                                $rowDetails->relationship->key,$dataTypeContent->{$row->field}
                                            )->first();
                                        }
                                    }
                                    ?>
                                    {{ $relationshipOptions->{$rowDetails->relationship->label} }}
                                @endif
                            @elseif($row->type == 'select_dropdown' && $dataTypeContent->{$row->field . '_page_slug'})
                                <a href="{{ $dataTypeContent->{$row->field . '_page_slug'} }}">{{ $dataTypeContent->{$row->field}  }}</a>
                            @elseif($row->type == 'select_multiple')
                                @if(property_exists($rowDetails, 'relationship'))
                                    <?php
                                    $BgColorClassArray = [
                                        'badge-info',
                                        'badge-default',
                                        'badge-success',
                                        'badge-primary',
                                        'badge-warning',
                                        'badge-danger'
                                    ];
                                    ?>
                                    @foreach($dataTypeContent->{$row->field} as $item)
                                        <?php
                                        $randPointer = mt_rand(0,5);
                                        $MultipleColorClass = $BgColorClassArray[$randPointer];
                                        ?>
                                        @if(isset($item->{$row->field . '_page_slug'})&&$item->{$row->field . '_page_slug'})
                                            <a href="{{ $item->{$row->field . '_page_slug'} }}">{{ $item->{$row->field} }}</a>@if(!$loop->last), @endif
                                        @else
                                            <span class="badge {{$MultipleColorClass}}">{{ $item->{$row->field} }}</span>
                                        @endif
                                    @endforeach

                                    {{-- $data->{$row->field}->implode($options->relationship->label, ', ') --}}
                                @elseif(property_exists($rowDetails, 'options'))
                                    @foreach($dataTypeContent->{$row->field} as $item)
                                        {{ $rowDetails->options->{$item} . (!$loop->last ? ', ' : '') }}
                                    @endforeach
                                @endif
                            @elseif($row->type == 'date')
                                {{ $rowDetails && property_exists($rowDetails, 'format') ? \Carbon\Carbon::parse($dataTypeContent->{$row->field})->formatLocalized($rowDetails->format) : $dataTypeContent->{$row->field} }}
                            @elseif($row->type == 'checkbox')
                                @if($rowDetails && property_exists($rowDetails, 'on') && property_exists($rowDetails, 'off'))
                                    @if($dataTypeContent->{$row->field})
                                    <span class="label label-info">{{ $rowDetails->on }}</span>
                                    @else
                                    <span class="label label-primary">{{ $rowDetails->off }}</span>
                                    @endif
                                @else
                                {{ $dataTypeContent->{$row->field} }}
                                @endif
                            @elseif($row->type == 'radio_btn' && isset($rowDetails->options) &&!empty($rowDetails->options->{$dataTypeContent->{$row->field}}))
                                <?php echo $rowDetails->options->{$dataTypeContent->{$row->field}};?>
                            @elseif($row->type == 'radio_btn' && isset($rowDetails->relationship))
                                @if( !method_exists( $dataType->model_name, camel_case($row->field) ) )
                                    <p class="label label-warning"><i class="voyager-warning"></i> Make sure to setup the appropriate relationship in the {{ camel_case($row->field) . '()' }} method of the {{ $dataType->model_name }} class.</p>
                                @else
                                    <?php
                                    $relationshipListMethod = camel_case($row->field) . 'List';
                                    if (method_exists($dataTypeContent, $relationshipListMethod)) {
                                        $relationshipOptions = $dataTypeContent->$relationshipListMethod();
                                    } else {
                                        $relationshipClass = $dataTypeContent->{camel_case($row->field)}()->getRelated();

                                        if (isset($rowDetails->relationship->where)) {
                                            $relationshipOptions = $relationshipClass::where(
                                                $rowDetails->relationship->where[0],
                                                $rowDetails->relationship->where[1]
                                            )->get();
                                        } else {
                                            $relationshipOptions = $relationshipClass::where(
                                                $rowDetails->relationship->key,$dataTypeContent->{$row->field}
                                            )->first();
                                        }
                                    }

                                    ?>
                                    {{ $relationshipOptions->{$rowDetails->relationship->label} }}
                                @endif
                            @elseif($row->type == 'select_dropdown' && $dataTypeContent->{$row->field . '_page_slug'})
                                <a href="{{ $dataTypeContent->{$row->field . '_page_slug'} }}">{{ $dataTypeContent->{$row->field}  }}</a>
                            @elseif($row->type == 'switch')
                                @if($rowDetails && property_exists($rowDetails, 'on') && property_exists($rowDetails, 'off'))
                                    @if($dataTypeContent->{$row->field})
                                        <span class="label label-info">{{ $rowDetails->on }}</span>
                                    @else
                                        <span class="label label-primary">{{ $rowDetails->off }}</span>
                                    @endif
                                @else
                                    {{ $dataTypeContent->{$row->field} }}
                                @endif
                            @elseif($row->type == 'rich_text_box')
                                @include('voyager::multilingual.input-hidden-bread-read')
                                <p>{{ strip_tags($dataTypeContent->{$row->field}, '<b><i><u>') }}</p>
                            @else
                                @include('voyager::multilingual.input-hidden-bread-read')
                                <p>{{ $dataTypeContent->{$row->field} }}</p>
                            @endif
                        </div><!-- panel-body -->
                        @if(!$loop->last)
                            <hr style="margin:0;">
                        @endif
                    @endforeach

                </div>
            </div>
        </div>
    </div>
@stop

@section('javascript')
    @if ($isModelTranslatable)
    <script>
        $(document).ready(function () {
            $('.side-body').multilingual();
        });
    </script>
    <script src="{{ voyager_asset('js/multilingual.js') }}"></script>
    @endif
@stop
